<template><div><p>本文档最新版为 <a href="https://learnku.com/docs/laravel/10.x" target="_blank" rel="noopener noreferrer">10.x</a>，旧版本可能放弃维护，推荐阅读最新版！</p>
<h2 id="日志记录" tabindex="-1"><a class="header-anchor" href="#日志记录"><span>日志记录</span></a></h2>
<ul>
<li><a href="#introduction">介绍</a></li>
<li><a href="#configuration">配置</a>
<ul>
<li><a href="#available-channel-drivers">可用通道驱动程序</a></li>
<li><a href="#channel-prerequisites">通道先决条件</a></li>
<li><a href="#logging-deprecation-warnings">日志弃用警告</a></li>
</ul>
</li>
<li><a href="#building-log-stacks">构建日志堆栈</a></li>
<li><a href="#writing-log-messages">编写日志消息</a>
<ul>
<li><a href="#contextual-information">上下文信息</a></li>
<li><a href="#writing-to-specific-channels">写入特定通道</a></li>
</ul>
</li>
<li><a href="#monolog-channel-customization">Monolog 通道定制</a>
<ul>
<li><a href="#customizing-monolog-for-channels">为通道定制 Monolog</a></li>
<li><a href="#creating-monolog-handler-channels">创建 Monolog 处理程序通道</a></li>
<li><a href="#creating-custom-channels-via-factories">通过工厂创建自定义通道</a></li>
</ul>
</li>
<li><a href="#tailing-log-messages-using-pail">使用 Pail 追踪日志消息</a>
<ul>
<li><a href="#pail-installation">安装</a></li>
<li><a href="#pail-usage">使用</a></li>
<li><a href="#pail-filtering-logs">日志过滤</a></li>
</ul>
</li>
</ul>
<h2 id="介绍" tabindex="-1"><a class="header-anchor" href="#介绍"><span>介绍</span></a></h2>
<p>为了帮助您更好地了解应用程序内部发生的情况，Laravel 提供了强大的日志记录服务，允许您将消息记录到文件、系统错误日志，甚至通过 Slack 通知整个团队。</p>
<p>Laravel 的日志记录基于「通道」。每个通道代表一种特定的日志记录方式。例如，<code v-pre>single</code> 通道将日志记录到单个日志文件，而 <code v-pre>slack</code> 通道则将日志消息发送到 Slack。根据消息的严重程度，日志消息可以被记录到多个通道中。</p>
<p>在底层，Laravel 使用了 <a href="https://github.com/Seldaek/monolog" target="_blank" rel="noopener noreferrer">Monolog</a> 库，该库支持多种强大的日志处理程序。Laravel 提供了简单的配置方式来配置这些处理程序，允许您自定义应用程序的日志处理方式。</p>
<h2 id="配置" tabindex="-1"><a class="header-anchor" href="#配置"><span>配置</span></a></h2>
<p>控制应用程序日志行为的所有配置选项都存储在 <code v-pre>config/logging.php</code> 配置文件中。该文件允许您配置应用程序的日志通道，因此请确保仔细查看每个可用通道及其选项。接下来，我们将详细介绍一些常见的选项。</p>
<p>默认情况下，Laravel 在记录消息时将使用 <code v-pre>stack</code> 通道。<code v-pre>stack</code> 通道用于将多个日志通道聚合成单个通道。有关构建堆栈的更多信息，请查看下面的<a href="#building-log-stacks">文档</a>。</p>
<h3 id="可用的通道驱动程序" tabindex="-1"><a class="header-anchor" href="#可用的通道驱动程序"><span>可用的通道驱动程序</span></a></h3>
<p>每个日志通道都由一个「 驱动程序」提供支持。该驱动程序确定日志消息实际记录的方式和位置。在每个 Laravel 应用程序中都可以使用以下日志通道驱动程序。大多数这些驱动程序的条目已经存在于您应用程序的 <code v-pre>config/logging.php</code> 配置文件中，因此请确保查看该文件以熟悉其内容：</p>
<p>| 名称 | 描述 | |--------------|------------------------------------------------| | `custom` | 调用指定工厂创建通道的驱动程序 | | `daily` | 基于 `RotatingFileHandler` 的 Monolog 驱动程序，每天轮换一次日志文件 | | `errorlog` | 基于 `ErrorLogHandler` 的 Monolog 驱动程序 | | `monolog` | 可使用任何受支持的 Monolog 处理程序的 Monolog 工厂驱动程序 | | `papertrail` | 基于 `SyslogUdpHandler` 的 Monolog 驱动程序 | | `single` | 单个文件或路径为基础的记录器通道（`StreamHandler`） | | `slack` | 基于 `SlackWebhookHandler` 的 Monolog 驱动程序 | | `stack` | 用于创建“多通道”通道的包装器 | | `syslog` | 基于 `SyslogHandler` 的 Monolog 驱动程序 |</p>
<blockquote>
<p>提醒：查看<a href="#monolog-channel-customization">高级通道定制文档</a>以了解有关 <code v-pre>monolog</code> 和 <code v-pre>custom</code> 驱动程序的更多信息。</p>
</blockquote>
<h4 id="配置通道名称" tabindex="-1"><a class="header-anchor" href="#配置通道名称"><span>配置通道名称</span></a></h4>
<p>默认情况下，Monolog 使用与当前环境匹配的「 通道名称」进行实例化，例如 <code v-pre>production</code> 或 <code v-pre>local</code>。要更改此值，您可以在通道的配置中添加一个 <code v-pre>name</code> 选项：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line">    <span class="token string single-quoted-string">'stack'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'stack'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'name'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'channel-name'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'channels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'single'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'slack'</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="通道先决条件" tabindex="-1"><a class="header-anchor" href="#通道先决条件"><span>通道先决条件</span></a></h3>
<h4 id="配置单通道和日志通道" tabindex="-1"><a class="header-anchor" href="#配置单通道和日志通道"><span>配置单通道和日志通道</span></a></h4>
<p><code v-pre>single</code> 和 <code v-pre>daily</code> 通道有三个可选的配置选项：<code v-pre>bubble</code>、<code v-pre>permission</code> 和 <code v-pre>locking</code>。</p>
<p>名称 | 描述 | 默认值 ------------- | ------------- | ------------- `bubble` | 指示消息在处理后是否应向上传递到其他通道 | `true` `locking` | 在写入文件之前尝试锁定日志文件 | `false` `permission` | 日志文件的权限 | `0644`</p>
<p>此外，<code v-pre>daily</code> 通道的保留策略可以通过 <code v-pre>LOG_DAILY_DAYS</code> 环境变量或设置 <code v-pre>days</code> 配置选项进行配置。</p>
<p>名称 | 描述 | 默认值 ------------- | ------------- | ------------- `days` | 应保留的日志文件天数 | `7`</p>
<h4 id="配置-papertrail-通道" tabindex="-1"><a class="header-anchor" href="#配置-papertrail-通道"><span>配置 Papertrail 通道</span></a></h4>
<p><code v-pre>papertrail</code> 通道需要 <code v-pre>host</code> 和 <code v-pre>port</code> 配置选项。这些可以通过 <code v-pre>PAPERTRAIL_URL</code> 和 <code v-pre>PAPERTRAIL_PORT</code> 环境变量定义。您可以在 <a href="https://help.papertrailapp.com/kb/configuration/configuring-centralized-logging-from-php-apps/#send-events-from-php-app" target="_blank" rel="noopener noreferrer">Papertrail</a> 获取这些值。</p>
<h4 id="配置-slack-通道" tabindex="-1"><a class="header-anchor" href="#配置-slack-通道"><span>配置 Slack 通道</span></a></h4>
<p><code v-pre>slack</code> 通道需要一个 <code v-pre>url</code> 配置选项。此值可以通过 <code v-pre>LOG_SLACK_WEBHOOK_URL</code> 环境变量定义。此 URL 应与您为 Slack 团队配置的 <a href="https://slack.com/apps/A0F7XDUAZ-incoming-webhooks" target="_blank" rel="noopener noreferrer">入站 Webhook</a> 匹配。</p>
<p>默认情况下，Slack 只会接收 <code v-pre>critical</code> 级别及以上的日志；但是，您可以使用 <code v-pre>LOG_LEVEL</code> 环境变量或通过修改 Slack 日志通道配置数组中的 <code v-pre>level</code> 配置选项来调整此设置。</p>
<h3 id="记录弃用警告" tabindex="-1"><a class="header-anchor" href="#记录弃用警告"><span>记录弃用警告</span></a></h3>
<p>PHP、Laravel 和其他库经常通知用户，它们的一些功能已被弃用，并将在将来的版本中移除。如果您希望记录这些弃用警告，可以使用 <code v-pre>LOG_DEPRECATIONS_CHANNEL</code> 环境变量或在应用程序的 <code v-pre>config/logging.php</code> 配置文件中指定您首选的 <code v-pre>deprecations</code> 日志通道：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'deprecations'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'channel'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_DEPRECATIONS_CHANNEL'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'null'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'trace'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_DEPRECATIONS_TRACE'</span><span class="token punctuation">,</span> <span class="token constant boolean">false</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line"><span class="token string single-quoted-string">'channels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token comment">// ...</span></span>
<span class="line"><span class="token punctuation">]</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>或者，您可以定义一个名为 <code v-pre>deprecations</code> 的日志通道。如果存在具有此名称的日志通道，它将始终用于记录弃用警告：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'channels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'deprecations'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'single'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'path'</span> <span class="token operator">=></span> <span class="token function">storage_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'logs/php-deprecation-warnings.log'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="构建日志堆栈" tabindex="-1"><a class="header-anchor" href="#构建日志堆栈"><span>构建日志堆栈</span></a></h3>
<p>如前所述，<code v-pre>stack</code> 驱动程序允许您将多个通道组合成一个便利的单个日志通道。为了说明如何使用日志堆栈，让我们看一个您可能在生产应用程序中看到的示例配置：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'channels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'stack'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'stack'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'channels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'syslog'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'slack'</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token comment">// [tl! add]</span></span>
<span class="line">        <span class="token string single-quoted-string">'ignore_exceptions'</span> <span class="token operator">=></span> <span class="token constant boolean">false</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token string single-quoted-string">'syslog'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'syslog'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'level'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_LEVEL'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'debug'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'facility'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_SYSLOG_FACILITY'</span><span class="token punctuation">,</span> <span class="token constant">LOG_USER</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'replace_placeholders'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">    <span class="token string single-quoted-string">'slack'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'slack'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'url'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_SLACK_WEBHOOK_URL'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'username'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_SLACK_USERNAME'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'Laravel Log'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'emoji'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_SLACK_EMOJI'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">':boom:'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'level'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_LEVEL'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'critical'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'replace_placeholders'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>让我们分解这个配置。首先，注意到我们的 <code v-pre>stack</code> 通道通过其 <code v-pre>channels</code> 选项聚合了另外两个通道：<code v-pre>syslog</code> 和 <code v-pre>slack</code>。因此，在记录消息时，这两个通道都有机会记录消息。然而，正如我们将在下文中看到的，这些通道是否实际记录消息可能取决于消息的严重性/“级别”。</p>
<h4 id="日志级别" tabindex="-1"><a class="header-anchor" href="#日志级别"><span>日志级别</span></a></h4>
<p>请注意上面示例中 <code v-pre>syslog</code> 和 <code v-pre>slack</code> 通道配置中存在的 <code v-pre>level</code> 配置选项。此项决定了消息必须达到最小 「级别」 才能被通道记录。Laravel 的日志服务采用 Monolog，提供 <a href="https://tools.ietf.org/html/rfc5424" target="_blank" rel="noopener noreferrer">RFC 5424 规范</a>中定义的所有日志级别。按严重程度降序排列的，这些日志级别是: <strong>emergency（紧急）</strong>, <strong>alert（警告）</strong>, <strong>critical（关键）</strong>, <strong>error（错误）</strong>, <strong>warning（警告）</strong>, <strong>notice（通知）</strong>, <strong>info（信息）</strong>, 和 <strong>debug（调试）</strong>。</p>
<p>因此，假设我们使用 <code v-pre>debug</code> 方法记录一条消息:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'An informational message.'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>根据我们的配置， <code v-pre>syslog</code> 渠道将把消息写入系统日志；但由于错误消息不是 <code v-pre>critical</code> 或以上级别，它不会被发送到 Slack。 然而, 如果我们记录一个 <code v-pre>emergency</code> 级别的消息，它将会被发送到系统日志和 Slack。 因为 <code v-pre>emergency</code> 级别高于这两个渠道的最低等级阈值:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">emergency</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'The system is down!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="写入日志消息" tabindex="-1"><a class="header-anchor" href="#写入日志消息"><span>写入日志消息</span></a></h2>
<p>你可以使用 <code v-pre>Log</code> <a href="https://learnku.com/docs/laravel/11.x/facadesmd/16656" target="_blank" rel="noopener noreferrer">门面</a> 将信息写入日志。如前所述，记录器提供了 <a href="https://tools.ietf.org/html/rfc5424" target="_blank" rel="noopener noreferrer">RFC 5424 规范</a> 中定义的八个日志级别: <strong>emergency（紧急）</strong>, <strong>alert（警告）</strong>, <strong>critical（关键）</strong>, <strong>error（错误）</strong>, <strong>warning（警告）</strong>, <strong>notice（通知）</strong>, <strong>info（信息）</strong>, 和 <strong>debug（调试）</strong>:</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">emergency</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">critical</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">warning</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">notice</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>您可以调用任何一个方法来记录相应级别的消息。默认情况下，消息将写入由您的 <code v-pre>logging</code> 配置文件配置的默认日志渠道进行写入：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers<span class="token punctuation">\</span>Controller</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>View<span class="token punctuation">\</span>View</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">UserController</span> <span class="token keyword">extends</span> <span class="token class-name">Controller</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 显示给定用户的个人资料。</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">show</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$id</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">View</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Showing the user profile for user: {id}'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token variable">$id</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user.profile'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'user'</span> <span class="token operator">=></span> <span class="token class-name static-context">User</span><span class="token operator">::</span><span class="token function">findOrFail</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="日志级别-1" tabindex="-1"><a class="header-anchor" href="#日志级别-1"><span>日志级别</span></a></h4>
<p>请注意上面示例中 <code v-pre>syslog</code> 和 <code v-pre>slack</code> 通道配置中存在的 <code v-pre>level</code> 配置选项。此选项确定必须记录消息的最小 「级别」 。Laravel的日志服务采用Monolog，提供<a href="https://tools.ietf.org/html/rfc5424" target="_blank" rel="noopener noreferrer">RFC 5424规范</a>中定义的所有日志级别。按严重程度递减的顺序，这些日志级别是：<strong>emergency</strong>，<strong>alert</strong>，<strong>critical</strong>，<strong>error</strong>，<strong>warning</strong>，<strong>notice</strong>，<strong>info</strong>和<strong>debug</strong>。</p>
<p>在我们的配置中，如果我们使用 <code v-pre>debug</code> 方法记录消息：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'An informational message.'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>根据我们的配置，<code v-pre>syslog</code> 渠道将把消息写入系统日志；但由于错误消息不是 <code v-pre>critical</code> 或以上级别，它不会被发送到 Slack。然而，如果我们记录一个 <code v-pre>emergency</code> 级别的消息，则会发送到系统日志和 Slack，因为 <code v-pre>emergency</code> 级别高于我们两个渠道的最小级别阈值：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">emergency</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'The system is down!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h2 id="写入日志消息-1" tabindex="-1"><a class="header-anchor" href="#写入日志消息-1"><span>写入日志消息</span></a></h2>
<p>您可以使用 <code v-pre>Log</code> <a href="https://learnku.com/docs/laravel/11.x/facades" target="_blank" rel="noopener noreferrer">facade</a> 向日志写入信息。正如之前提到的，日志记录器提供了 <a href="https://tools.ietf.org/html/rfc5424" target="_blank" rel="noopener noreferrer">RFC 5424 规范</a> 中定义的八个日志级别：<strong>emergency</strong>、<strong>alert</strong>、<strong>critical</strong>、<strong>error</strong>、<strong>warning</strong>、<strong>notice</strong>、<strong>info</strong> 和 <strong>debug</strong>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">emergency</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">alert</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">critical</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">error</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">warning</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">notice</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">debug</span><span class="token punctuation">(</span><span class="token variable">$message</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>您可以调用其中任何一个方法来记录相应级别的消息。默认情况下，该消息将根据您的 <code v-pre>logging</code> 配置文件配置的默认日志渠道进行写入：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Controllers<span class="token punctuation">\</span>Controller</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">App<span class="token punctuation">\</span>Models<span class="token punctuation">\</span>User</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>View<span class="token punctuation">\</span>View</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">UserController</span> <span class="token keyword">extends</span> <span class="token class-name">Controller</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 显示指定用户的个人资料</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">show</span><span class="token punctuation">(</span><span class="token keyword type-hint">string</span> <span class="token variable">$id</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">View</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Showing the user profile for user: {id}'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token variable">$id</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token function">view</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'user.profile'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'user'</span> <span class="token operator">=></span> <span class="token class-name static-context">User</span><span class="token operator">::</span><span class="token function">findOrFail</span><span class="token punctuation">(</span><span class="token variable">$id</span><span class="token punctuation">)</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="上下文信息" tabindex="-1"><a class="header-anchor" href="#上下文信息"><span>上下文信息</span></a></h3>
<p>可以向日志方法传递一组上下文数据。这些上下文数据将与日志消息一起格式化和显示：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'User {id} failed to login.'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token variable">$user</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>偶尔，您可能希望指定一些上下文信息，这些信息应包含在特定频道中所有随后的日志条目中。例如，您可能希望记录与应用程序的每个传入请求相关联的请求 ID。为了实现这一目的，您可以调用 <code v-pre>Log</code> 门面的 <code v-pre>withContext</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Middleware</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Closure</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Request</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Str</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Symfony<span class="token punctuation">\</span>Component<span class="token punctuation">\</span>HttpFoundation<span class="token punctuation">\</span>Response</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">AssignRequestId</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * Handle an incoming request.</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Closure</span>(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">handle</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Request</span> <span class="token variable">$request</span><span class="token punctuation">,</span> <span class="token class-name type-declaration">Closure</span> <span class="token variable">$next</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">Response</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$requestId</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword type-casting">string</span><span class="token punctuation">)</span> <span class="token class-name static-context">Str</span><span class="token operator">::</span><span class="token function">uuid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">withContext</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'request-id'</span> <span class="token operator">=></span> <span class="token variable">$requestId</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$response</span> <span class="token operator">=</span> <span class="token variable">$next</span><span class="token punctuation">(</span><span class="token variable">$request</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$response</span><span class="token operator">-></span><span class="token property">headers</span><span class="token operator">-></span><span class="token function">set</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Request-Id'</span><span class="token punctuation">,</span> <span class="token variable">$requestId</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$response</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果要在_所有_日志频道之间共享上下文信息，则可以调用 <code v-pre>Log::shareContext()</code> 方法。此方法将向所有已创建的频道提供上下文信息：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Middleware</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Closure</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Request</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Str</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Symfony<span class="token punctuation">\</span>Component<span class="token punctuation">\</span>HttpFoundation<span class="token punctuation">\</span>Response</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">AssignRequestId</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * Handle an incoming request.</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Closure</span>(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">handle</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Request</span> <span class="token variable">$request</span><span class="token punctuation">,</span> <span class="token class-name type-declaration">Closure</span> <span class="token variable">$next</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">Response</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$requestId</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword type-casting">string</span><span class="token punctuation">)</span> <span class="token class-name static-context">Str</span><span class="token operator">::</span><span class="token function">uuid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">shareContext</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'request-id'</span> <span class="token operator">=></span> <span class="token variable">$requestId</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token comment">// ...</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p>[注意]<br>
如果在处理排队作业时需要共享日志上下文，可以使用 <a href="https://learnku.com/docs/laravel/11.x/queues#job-middleware" target="_blank" rel="noopener noreferrer">job middleware</a>.</p>
</blockquote>
<h3 id="上下文信息-1" tabindex="-1"><a class="header-anchor" href="#上下文信息-1"><span>上下文信息</span></a></h3>
<p>可以向日志方法传递一组上下文数据。这些上下文数据将与日志消息一起格式化和显示：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'User {id} failed to login.'</span><span class="token punctuation">,</span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'id'</span> <span class="token operator">=></span> <span class="token variable">$user</span><span class="token operator">-></span><span class="token property">id</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>偶尔，您可能希望指定一些上下文信息，这些信息应包含在特定频道中所有随后的日志条目中。例如，您可能希望记录与应用程序的每个传入请求相关联的请求ID。为了实现这一目的，您可以调用 <code v-pre>Log</code> 门面的 <code v-pre>withContext</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Middleware</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Closure</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Request</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Str</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Symfony<span class="token punctuation">\</span>Component<span class="token punctuation">\</span>HttpFoundation<span class="token punctuation">\</span>Response</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">AssignRequestId</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 处理收到的请求。</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Closure</span>(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">handle</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Request</span> <span class="token variable">$request</span><span class="token punctuation">,</span> <span class="token class-name type-declaration">Closure</span> <span class="token variable">$next</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">Response</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$requestId</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword type-casting">string</span><span class="token punctuation">)</span> <span class="token class-name static-context">Str</span><span class="token operator">::</span><span class="token function">uuid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">withContext</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'request-id'</span> <span class="token operator">=></span> <span class="token variable">$requestId</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$response</span> <span class="token operator">=</span> <span class="token variable">$next</span><span class="token punctuation">(</span><span class="token variable">$request</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token variable">$response</span><span class="token operator">-></span><span class="token property">headers</span><span class="token operator">-></span><span class="token function">set</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Request-Id'</span><span class="token punctuation">,</span> <span class="token variable">$requestId</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token keyword">return</span> <span class="token variable">$response</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果要在_所有_日志频道之间共享上下文信息，则可以调用 <code v-pre>Log::shareContext()</code> 方法。此方法将向所有已创建的频道提供上下文信息，以及随后创建的任何频道。</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Middleware</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Closure</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Http<span class="token punctuation">\</span>Request</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Str</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Symfony<span class="token punctuation">\</span>Component<span class="token punctuation">\</span>HttpFoundation<span class="token punctuation">\</span>Response</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">AssignRequestId</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 处理收到的请求。</span>
<span class="line">     *</span>
<span class="line">     * <span class="token keyword">@param</span>  <span class="token class-name"><span class="token punctuation">\</span>Closure</span>(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response)  $next</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">handle</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Request</span> <span class="token variable">$request</span><span class="token punctuation">,</span> <span class="token class-name type-declaration">Closure</span> <span class="token variable">$next</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">Response</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token variable">$requestId</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token keyword type-casting">string</span><span class="token punctuation">)</span> <span class="token class-name static-context">Str</span><span class="token operator">::</span><span class="token function">uuid</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">shareContext</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'request-id'</span> <span class="token operator">=></span> <span class="token variable">$requestId</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line">        <span class="token comment">// ...</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p><strong>注意</strong><br>
如果您需要在处理队列任务时共享日志上下文,可以使用 <a href="https://learnku.com/docs/laravel/11.x/queues#job-middleware" target="_blank" rel="noopener noreferrer">job middleware</a>.</p>
</blockquote>
<h3 id="写入指定通道" tabindex="-1"><a class="header-anchor" href="#写入指定通道"><span>写入指定通道</span></a></h3>
<p>有时，你可能希望将消息记录到应用程序默认通道以外的通道。你可以使用 <code v-pre>Log</code> facade 的 <code v-pre>channel</code> 方法来检索并记录配置文件中定义的任何通道：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">channel</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'slack'</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Something happened!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你想创建一个由多个通道组成的按需记录堆栈，可以使用 <code v-pre>stack</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">stack</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'single'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'slack'</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Something happened!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="按需通道" tabindex="-1"><a class="header-anchor" href="#按需通道"><span>按需通道</span></a></h4>
<p>还可以创建一个按需通道，方法是在运行时提供配置，而无需将该配置包含在应用程序的 <code v-pre>logging</code> 配置文件中。为此，可以将配置数组传递给 <code v-pre>Log</code> facade 的 <code v-pre>build</code> 方法：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">  <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'single'</span><span class="token punctuation">,</span></span>
<span class="line">  <span class="token string single-quoted-string">'path'</span> <span class="token operator">=></span> <span class="token function">storage_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'logs/custom.log'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Something happened!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>你可能还希望在按需记录堆栈中包含一个按需通道。可以通过将按需通道实例包含在传递给 <code v-pre>stack</code> 方法的数组中来实现：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Support<span class="token punctuation">\</span>Facades<span class="token punctuation">\</span>Log</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token variable">$channel</span> <span class="token operator">=</span> <span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">build</span><span class="token punctuation">(</span><span class="token punctuation">[</span></span>
<span class="line">  <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'single'</span><span class="token punctuation">,</span></span>
<span class="line">  <span class="token string single-quoted-string">'path'</span> <span class="token operator">=></span> <span class="token function">storage_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'logs/custom.log'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token class-name static-context">Log</span><span class="token operator">::</span><span class="token function">stack</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token string single-quoted-string">'slack'</span><span class="token punctuation">,</span> <span class="token variable">$channel</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token operator">-></span><span class="token function">info</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'Something happened!'</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="monolog-通道定制" tabindex="-1"><a class="header-anchor" href="#monolog-通道定制"><span>Monolog 通道定制</span></a></h2>
<h3 id="为通道定制-monolog" tabindex="-1"><a class="header-anchor" href="#为通道定制-monolog"><span>为通道定制 Monolog</span></a></h3>
<p>有时，你可能需要完全控制 Monolog 如何配置现有通道。例如，你可能希望为 Laravel 内置的 <code v-pre>single</code> 通道配置自定义的 Monolog <code v-pre>FormatterInterface</code> 实现。</p>
<p>要开始，请在通道配置中定义 <code v-pre>tap</code> 数组。<code v-pre>tap</code> 数组应包含一系列类，这些类在创建 Monolog 实例后应有机会自定义（或 「tab」）它。没有这些类应放置在何处的惯例位置，因此您可以在应用程序中创建一个目录以包含这些类：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'single'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'single'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'tap'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token class-name class-name-fully-qualified static-context">App<span class="token punctuation">\</span>Logging<span class="token punctuation">\</span>CustomizeFormatter</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'path'</span> <span class="token operator">=></span> <span class="token function">storage_path</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'logs/laravel.log'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'level'</span> <span class="token operator">=></span> <span class="token function">env</span><span class="token punctuation">(</span><span class="token string single-quoted-string">'LOG_LEVEL'</span><span class="token punctuation">,</span> <span class="token string single-quoted-string">'debug'</span><span class="token punctuation">)</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'replace_placeholders'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>一旦你在通道上配置了 <code v-pre>tap</code> 选项，你就可以定义一个类来自定义你的 Monolog 实例。这个类只需要一个方法：<code v-pre>__invoke</code>，它接收一个 <code v-pre>Illuminate\Log\Logger</code> 实例。<code v-pre>Illuminate\Log\Logger</code> 实例代理所有方法调用到底层的 Monolog 实例：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Logging</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Illuminate<span class="token punctuation">\</span>Log<span class="token punctuation">\</span>Logger</span><span class="token punctuation">;</span></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Monolog<span class="token punctuation">\</span>Formatter<span class="token punctuation">\</span>LineFormatter</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">CustomizeFormatter</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 自定义给定的日志记录器实例。</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">__invoke</span><span class="token punctuation">(</span><span class="token class-name type-declaration">Logger</span> <span class="token variable">$logger</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token keyword return-type">void</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">foreach</span> <span class="token punctuation">(</span><span class="token variable">$logger</span><span class="token operator">-></span><span class="token function">getHandlers</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token keyword">as</span> <span class="token variable">$handler</span><span class="token punctuation">)</span> <span class="token punctuation">{</span></span>
<span class="line">            <span class="token variable">$handler</span><span class="token operator">-></span><span class="token function">setFormatter</span><span class="token punctuation">(</span><span class="token keyword">new</span> <span class="token class-name">LineFormatter</span><span class="token punctuation">(</span></span>
<span class="line">                <span class="token string single-quoted-string">'[%datetime%] %channel%.%level_name%: %message% %context% %extra%'</span></span>
<span class="line">            <span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">        <span class="token punctuation">}</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><blockquote>
<p><strong>注意</strong><br>
所有的 「tab」类都由 <a href="https://learnku.com/docs/laravel/11.x/container" target="_blank" rel="noopener noreferrer">服务容器</a> 解析，因此它们所需的任何构造函数依赖关系都将自动注入。</p>
</blockquote>
<h3 id="创建-monolog-处理程序通道" tabindex="-1"><a class="header-anchor" href="#创建-monolog-处理程序通道"><span>创建 Monolog 处理程序通道</span></a></h3>
<p>Monolog 有多种 <a href="https://github.com/Seldaek/monolog/tree/main/src/Monolog/Handler" target="_blank" rel="noopener noreferrer">可用的处理程序</a>，而 Laravel 并没有为每个处理程序内置通道。在某些情况下，你可能希望创建一个自定义通道，它仅是一个特定的 Monolog 处理程序实例，该处理程序没有相应的 Laravel 日志驱动程序。这些通道可以使用 <code v-pre>monolog</code> 驱动程序轻松创建。</p>
<p>使用 <code v-pre>monolog</code> 驱动程序时，<code v-pre>handler</code> 配置选项用于指定将实例化哪个处理程序。可选地，可以使用 <code v-pre>with</code> 配置选项指定处理程序需要的任何构造函数参数：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'logentries'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'driver'</span>  <span class="token operator">=></span> <span class="token string single-quoted-string">'monolog'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'handler'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Handler<span class="token punctuation">\</span>SyslogUdpHandler</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'with'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'host'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'my.logentries.internal.datahubhost.company.com'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'port'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'10000'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="monolog-格式化程序" tabindex="-1"><a class="header-anchor" href="#monolog-格式化程序"><span>Monolog 格式化程序</span></a></h4>
<p>使用 <code v-pre>monolog</code> 驱动程序时，Monolog <code v-pre>LineFormatter</code> 将用作默认格式化程序。但是，你可以使用 <code v-pre>formatter</code> 和 <code v-pre>formatter_with</code> 配置选项自定义传递给处理程序的格式化程序类型：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'browser'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'monolog'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'handler'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Handler<span class="token punctuation">\</span>BrowserConsoleHandler</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'formatter'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Formatter<span class="token punctuation">\</span>HtmlFormatter</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'formatter_with'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'dateFormat'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'Y-m-d'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>如果你使用的是能够提供自己的格式化程序的 Monolog 处理程序，你可以将 <code v-pre>formatter</code> 配置选项的值设置为 <code v-pre>default</code>：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'newrelic'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'monolog'</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'handler'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Handler<span class="token punctuation">\</span>NewRelicHandler</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token string single-quoted-string">'formatter'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'default'</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="monolog-处理器" tabindex="-1"><a class="header-anchor" href="#monolog-处理器"><span>Monolog 处理器</span></a></h4>
<p>Monolog 也可以在记录消息之前对其进行处理。你可以创建你自己的处理器或使用 <a href="https://github.com/Seldaek/monolog/tree/main/src/Monolog/Processor" target="_blank" rel="noopener noreferrer">Monolog 提供的现有处理器</a>。</p>
<p>如果你想为 <code v-pre>monolog</code> 驱动定制处理器，请在通道的配置中加入 <code v-pre>processors</code> 配置值：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"> <span class="token string single-quoted-string">'memory'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">     <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'monolog'</span><span class="token punctuation">,</span></span>
<span class="line">     <span class="token string single-quoted-string">'handler'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Handler<span class="token punctuation">\</span>StreamHandler</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">     <span class="token string single-quoted-string">'with'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">         <span class="token string single-quoted-string">'stream'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'php://stderr'</span><span class="token punctuation">,</span></span>
<span class="line">     <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">     <span class="token string single-quoted-string">'processors'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">         <span class="token comment">// 简单的语法...</span></span>
<span class="line">         <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Processor<span class="token punctuation">\</span>MemoryUsageProcessor</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line"></span>
<span class="line">         <span class="token comment">// 可选...</span></span>
<span class="line">         <span class="token punctuation">[</span></span>
<span class="line">            <span class="token string single-quoted-string">'processor'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">Monolog<span class="token punctuation">\</span>Processor<span class="token punctuation">\</span>PsrLogMessageProcessor</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">            <span class="token string single-quoted-string">'with'</span> <span class="token operator">=></span> <span class="token punctuation">[</span><span class="token string single-quoted-string">'removeUsedContextFields'</span> <span class="token operator">=></span> <span class="token constant boolean">true</span><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line">     <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"> <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="通过工厂创建自定义通道" tabindex="-1"><a class="header-anchor" href="#通过工厂创建自定义通道"><span>通过工厂创建自定义通道</span></a></h3>
<p>如果你想定义一个完全自定义的通道，你可以在其中完全控制 Monolog 的实例化和配置，你可以在 <code v-pre>config/logging.php</code> 配置文件中指定 <code v-pre>custom</code> 驱动程序类型。你的配置应该包括一个 <code v-pre>via</code> 选项，其中包含将被调用以创建 Monolog 实例的工厂类的名称：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token string single-quoted-string">'channels'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">    <span class="token string single-quoted-string">'example-custom-channel'</span> <span class="token operator">=></span> <span class="token punctuation">[</span></span>
<span class="line">        <span class="token string single-quoted-string">'driver'</span> <span class="token operator">=></span> <span class="token string single-quoted-string">'custom'</span><span class="token punctuation">,</span></span>
<span class="line">        <span class="token string single-quoted-string">'via'</span> <span class="token operator">=></span> <span class="token class-name class-name-fully-qualified static-context">App<span class="token punctuation">\</span>Logging<span class="token punctuation">\</span>CreateCustomLogger</span><span class="token operator">::</span><span class="token keyword">class</span><span class="token punctuation">,</span></span>
<span class="line">    <span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"><span class="token punctuation">]</span><span class="token punctuation">,</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>配置好 <code v-pre>custom</code> 驱动通道后，你就可以定义创建你的 Monolog 实例的类了。这个类只需要一个 <code v-pre>__invoke</code> 方法，该方法应该返回 Monolog 记录器实例。该方法将接收通道配置数组作为唯一参数：</p>
<div class="language-php line-numbers-mode" data-highlighter="prismjs" data-ext="php" data-title="php"><pre v-pre class="language-php"><code><span class="line"><span class="token php language-php"><span class="token delimiter important">&lt;?php</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">namespace</span> <span class="token package">App<span class="token punctuation">\</span>Logging</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">use</span> <span class="token package">Monolog<span class="token punctuation">\</span>Logger</span><span class="token punctuation">;</span></span>
<span class="line"></span>
<span class="line"><span class="token keyword">class</span> <span class="token class-name-definition class-name">CreateCustomLogger</span></span>
<span class="line"><span class="token punctuation">{</span></span>
<span class="line">    <span class="token doc-comment comment">/**</span>
<span class="line">     * 创建一个自定义 Monolog 实例。</span>
<span class="line">     */</span></span>
<span class="line">    <span class="token keyword">public</span> <span class="token keyword">function</span> <span class="token function-definition function">__invoke</span><span class="token punctuation">(</span><span class="token keyword type-hint">array</span> <span class="token variable">$config</span><span class="token punctuation">)</span><span class="token punctuation">:</span> <span class="token class-name return-type">Logger</span></span>
<span class="line">    <span class="token punctuation">{</span></span>
<span class="line">        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">Logger</span><span class="token punctuation">(</span><span class="token comment">/* ... */</span><span class="token punctuation">)</span><span class="token punctuation">;</span></span>
<span class="line">    <span class="token punctuation">}</span></span>
<span class="line"><span class="token punctuation">}</span></span>
<span class="line"></span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="使用-pail-跟踪日志消息" tabindex="-1"><a class="header-anchor" href="#使用-pail-跟踪日志消息"><span>使用 Pail 跟踪日志消息</span></a></h2>
<p>你可能经常需要跟踪你的应用程序的日志。例如，调试问题或监视应用程序的日志以了解特定类型的错误。</p>
<p>Laravel Pail 包允许你直接从命令行轻松深入 Laravel 应用程序的日志文件。与标准的 <code v-pre>tail</code> 命令不同，Pail 旨在与任何日志驱动（包括 Sentry 或 Flare）一起工作。此外，Pail 提供了一组有用的过滤器，帮助你找到所需的内容。</p>
<p><img src="https://laravel.com/img/docs/pail-example.png" alt="pail-example.png"></p>
<h3 id="安装" tabindex="-1"><a class="header-anchor" href="#安装"><span>安装</span></a></h3>
<blockquote>
<p><strong>注意</strong><br>
Laravel Pail 需要 <a href="https://php.net/releases/" target="_blank" rel="noopener noreferrer">PHP 8.2+</a> 和 <a href="https://www.php.net/manual/en/book.pcntl.php" target="_blank" rel="noopener noreferrer">PCNTL</a> 扩展。</p>
</blockquote>
<p>首先，请使用 Composer 包管理器将 Pail 安装到你的项目中：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line"><span class="token function">composer</span> require laravel/pail</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="使用" tabindex="-1"><a class="header-anchor" href="#使用"><span>使用</span></a></h3>
<p>要开始跟踪日志，请运行 <code v-pre>pail</code> 命令：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>使用 <code v-pre>-v</code> 选项增加输出的详细程度并避免截断（…）：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail <span class="token parameter variable">-v</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>为了获得最详细的输出并显示异常堆栈跟踪，请使用 <code v-pre>-vv</code> 选项</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail <span class="token parameter variable">-vv</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><p>要停止跟踪日志，随时按 <code v-pre>Ctrl+C</code>。</p>
<h3 id="过滤日志" tabindex="-1"><a class="header-anchor" href="#过滤日志"><span>过滤日志</span></a></h3>
<h4 id="filter" tabindex="-1"><a class="header-anchor" href="#filter"><span><code v-pre>--filter</code></span></a></h4>
<p>你可以使用 <code v-pre>--filter</code> 选项按类型、文件、消息和堆栈跟踪内容过滤日志：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail <span class="token parameter variable">--filter</span><span class="token operator">=</span><span class="token string">"QueryException"</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="message" tabindex="-1"><a class="header-anchor" href="#message"><span><code v-pre>--message</code></span></a></h4>
<p>若要仅根据日志消息进行过滤，可以使用 <code v-pre>--message</code> 选项：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail <span class="token parameter variable">--message</span><span class="token operator">=</span><span class="token string">"User created"</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="level" tabindex="-1"><a class="header-anchor" href="#level"><span><code v-pre>--level</code></span></a></h4>
<p><code v-pre>--level</code> 选项可用于按<a href="#log-levels">日志级别</a>过滤日志：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail <span class="token parameter variable">--level</span><span class="token operator">=</span>error</span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="user" tabindex="-1"><a class="header-anchor" href="#user"><span><code v-pre>--user</code></span></a></h4>
<p>如需仅显示给定用户认证期间记录的日志，你可以将用户的 ID 提供给 <code v-pre>--user</code> 选项：</p>
<div class="language-bash line-numbers-mode" data-highlighter="prismjs" data-ext="sh" data-title="sh"><pre v-pre class="language-bash"><code><span class="line">php artisan pail <span class="token parameter variable">--user</span><span class="token operator">=</span><span class="token number">1</span></span>
<span class="line"></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><blockquote>
<p>本译文仅用于学习和交流目的，转载请务必注明文章译者、出处、和本文链接<br>
我们的翻译工作遵照 <a href="https://learnku.com/docs/guide/cc4.0/6589" target="_blank" rel="noopener noreferrer">CC 协议</a>，如果我们的工作有侵犯到您的权益，请及时联系我们。</p>
</blockquote>
<hr>
<blockquote>
<p>原文地址：<a href="https://learnku.com/docs/laravel/11.x/loggingmd/16670" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/lo...</a></p>
<p>译文地址：<a href="https://learnku.com/docs/laravel/11.x/loggingmd/16670" target="_blank" rel="noopener noreferrer">https://learnku.com/docs/laravel/11.x/lo...</a></p>
</blockquote>
</div></template>


